package com.vincent.tvui;

import android.content.Context;
import android.util.AttributeSet;

import java.util.Map;

/**
 * 项目：TvLauncher 作者：907357 时间：2016/10/13 17:42 版本：1.0 描述：描述内容
 */

public class ImageView extends android.widget.ImageView implements CellView {

    private static final String IMAGE_RUL = "imageUrl";

    private String mImageUrl;
    private CellViewController mCellViewController;

    public ImageView(Context context) {
        super(context);
    }

    public ImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void setStyles(Map<String, String> styles) {
        mImageUrl = styles.get(IMAGE_RUL);


        setScaleType(ScaleType.FIT_XY);
    }

    @Override
    public void setController(CellViewController controller) {
        this.mCellViewController = controller;
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (mImageUrl != null && !mImageUrl.equals("")) {
            loadImage(mImageUrl);
        }
    }

    public void loadImage(String imageUrl) {
        if (mCellViewController != null) {
            mCellViewController.loadImage(this, imageUrl);
        }
    }


}
